package org;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.Restrictions;

import vo.Custom;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class Login2Action extends ActionSupport {
	private String customname;
	private String password;

	public String getUsername() {
		return customname;
	}

	public void setCustomname(String customname) {
		this.customname = customname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		SessionFactory sf = new Configuration().configure()
				.buildSessionFactory();
		Session session = sf.openSession();
		session.beginTransaction();
		List list = session.createCriteria(Custom.class)
				.add(Restrictions.eq("customname", customname))
				.add(Restrictions.eq("password", password)).list();
		if(list.size()>0)
		{
			Custom custom = (Custom) list.get(0);
			ActionContext.getContext().getSession().put("custom", custom);
			session.getTransaction().commit();
			session.close();
			return SUCCESS;
		}
			

		return ERROR;
	}

}
